2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Content;
7 using Microsoft.Xna.Framework.Graphics;
9 namespace SuperPolarity
13 public Texture2D PlayerTexture;
14 public Vector2 Position;
15 public Vector2 Origin;
18 public int Multiplier;
27 float AccelerationRate;
28 ParticleEngine particleEngine;
32 get { return PlayerTexture.Width; }
37 get { return PlayerTexture.Height; }
40 public void Initialize(ContentManager Content, Texture2D texture, Vector2 position)
42 PlayerTexture = texture;
49 Origin = new Vector2(PlayerTexture.Width / 2, PlayerTexture.Height / 2);
50 Velocity = new Vector2(0, 0);
51 Acceleration = new Vector2(0, 0);
54 AccelerationRate = 10;
56 List<Texture2D> texturesList = new List<Texture2D>();
57 texturesList.Add(Content.Load<Texture2D>("Graphics\\circle"));
58 texturesList.Add(Content.Load<Texture2D>("Graphics\\diamond"));
59 texturesList.Add(Content.Load<Texture2D>("Graphics\\star"));
61 particleEngine = new ParticleEngine(texturesList, Position);
68 InputController.Bind("moveX", HandleHorizontalMovement);
69 InputController.Bind("moveY", HandleVerticalMovement);
72 public void HandleHorizontalMovement(float value)
74 Acceleration.X = value * AccelerationRate;
77 public void HandleVerticalMovement(float value)
79 Acceleration.Y = value * AccelerationRate;
82 public void AutoDeccelerate(GameTime gameTime)
84 if (Acceleration.X == 0 && Velocity.X > 0) {
85 if (AccelerationRate * gameTime.ElapsedGameTime.TotalSeconds > Velocity.X)
92 Acceleration.X = -AccelerationRate;
96 if (Acceleration.X == 0 && Velocity.X < 0)
98 if (-AccelerationRate * gameTime.ElapsedGameTime.TotalSeconds < Velocity.X)
105 Acceleration.X = AccelerationRate;
109 if (Acceleration.Y == 0 && Velocity.Y > 0)
111 if (AccelerationRate * gameTime.ElapsedGameTime.TotalSeconds > Velocity.Y)
118 Acceleration.Y = -AccelerationRate;
122 if (Acceleration.Y == 0 && Velocity.Y < 0)
124 if (-AccelerationRate * gameTime.ElapsedGameTime.TotalSeconds < Velocity.Y)
131 Acceleration.Y = AccelerationRate;
136 public void Update(GameTime gameTime)
140 particleEngine.EmitterLocation = Position;
141 particleEngine.Update();
144 public void Move(GameTime gameTime)
146 AutoDeccelerate(gameTime);
148 Velocity.X = Velocity.X + Acceleration.X * (float) gameTime.ElapsedGameTime.TotalSeconds;
149 Velocity.Y = Velocity.Y + Acceleration.Y * (float) gameTime.ElapsedGameTime.TotalSeconds;
151 if (Velocity.X > MaxVelocity)
153 Velocity.X = MaxVelocity;
156 if (Velocity.X < -MaxVelocity)
158 Velocity.X = -MaxVelocity;
161 if (Velocity.Y > MaxVelocity)
163 Velocity.Y = MaxVelocity;
166 if (Velocity.Y < -MaxVelocity)
168 Velocity.Y = -MaxVelocity;
171 Position.X = Position.X + Velocity.X;
172 Position.Y = Position.Y + Velocity.Y;
175 public void ChangeAngle()
177 Angle = (float) Math.Atan2(Velocity.Y, Velocity.X);
180 public void Draw(SpriteBatch spriteBatch)
182 particleEngine.Draw(spriteBatch);
183 spriteBatch.Draw(PlayerTexture, Position, null, Color.White, Angle, Origin, 1f, SpriteEffects.None, 0f);